package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/binary-tree-cameras/
 * @create 2025/9/27 10:04
 * @since JDK17
 */

public class Solution72 {
    int ans;
    int dfs(TreeNode x) {
        if (x == null) {
            return 1;
        }
        int l = dfs(x.left), r = dfs(x.right);
        if (l == 0 || r == 0) {
            ans++;  // x上必须放相机
            return 2;
        }
        if (l == 1 && r == 1) {
            return 0;
        }
        return 1;
    }
    public int minCameraCover(TreeNode root) {
        if (dfs(root) == 0) {
            ans++;
        }
        return ans;
    }
}
